package com.kaifamiao.www.Thread.do0927;

import java.time.LocalTime;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class FixedThreadPoolDemo {
    public static void main(String[] args) {
        /**
         * FixedThreadPool固定个数的线程池，线程处于空闲状态时不会被回收。
         * 如果工作线程数达到线程池初始的最大数，提交的任务进入池对列
         */
        ExecutorService pool = Executors.newFixedThreadPool(3);//核心线程数量
        System.out.println("当前时间" + LocalTime.now());
        for (int i = 0; i < 10; i++) {
            int number = i;
            pool.execute(new Runnable() {
                @Override
                public void run() {
                    System.out.println("当前时间" + LocalTime.now() + ",线程：" + Thread.currentThread().getName() + ",序号:" + number);
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            });
        }
    }
}